import java.util.concurrent.ArrayBlockingQueue;

/**
 * 堵塞队列
 * 1.数据结构   栈和队列
 *
 * 2.堵塞队列
 *     2.1
 */
public class BlockingQueueDemo {

    public static void main(String[] args) {
        ArrayBlockingQueue<String> blockingQueue = new ArrayBlockingQueue<>(3);

        //        //true
//        System.out.println(blockingQueue.add("a"));
//        System.out.println(blockingQueue.add("b"));
//        System.out.println(blockingQueue.add("c"));
//        //再加就抛异常， 队列已满
//        System.out.println(blockingQueue.add("d"));


        //得到队首
//        System.out.println(blockingQueue.element());

//        System.out.println(blockingQueue.remove());
//        System.out.println(blockingQueue.remove());
//        System.out.println(blockingQueue.remove());

        //空，抛出异常
//        System.out.println(blockingQueue.remove());

        //队列不满返回true
        System.out.println(blockingQueue.offer("a"));
        System.out.println(blockingQueue.offer("b"));
        System.out.println(blockingQueue.offer("c"));

        //队满返回false
        System.out.println(blockingQueue.offer("d"));
    }
}
